﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using UserControl;
using Module;


public partial class Coupon2 : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        Response.AppendHeader("P3P", "CP=CAO PSA OUR");
        if (!Page.IsPostBack)
        {

            //表
            string table = "Coupon2";
            string couponno = string.Empty;
            string sql = string.Empty;

            //一次取一个
            if (HttpContext.Current.Request.Cookies[table] != null)
            {
                couponno = HttpContext.Current.Request.Cookies[table].Value;
            }

            //一次取一个
            if (couponno == "")
            {
                sql = "select top 1 Couponno From " + table + " where status=0  order by newid()";
                DataTable coupDatas = Util.loadSql(sql);
                if (coupDatas.Rows.Count > 0)
                {
                    couponno = Util.objectToString(coupDatas.Rows[0]["Couponno"]);

                    HttpCookie cookie = new HttpCookie(table);
                    cookie.Path = "/";
                    cookie.Expires = System.DateTime.Now.AddMinutes(10);
                    cookie.Value = couponno;
                    HttpContext.Current.Response.Cookies.Add(cookie); ;

                    sql = "update " + table + " set status=1 where Couponno='" + couponno + "'";
                    Util.ExcSql(sql);
                }
            }
            this.lbl_couponno.Text = couponno;
        }
    }
}
